package com.zbkj.admin.controller.brand;

import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.CommonBatchRequest;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.TraceableOrderSearchBrandRequest;
import com.zbkj.common.request.TraceableOrderSearchRequest;
import com.zbkj.common.response.TraceableOrderDetailBrandResponse;
import com.zbkj.common.response.TraceableOrderDetailResponse;
import com.zbkj.common.response.TraceableOrderPageDataBrandResponse;
import com.zbkj.common.response.TraceableOrderPageDataResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.TraceableOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 品牌商溯源订单管理 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/brand/traceable/order")
@Api(tags = "品牌商溯源订单管理", description = "商户购买监控，蓝牙发射器等溯源套餐生成的订单") //配合swagger使用

public class BrandTraceableOrderController {
    @Autowired
    private TraceableOrderService traceableOrderService;

    /**
     * 分页显示溯源订单表
     *
     * @param request          搜索条件
     * @param pageParamRequest 分页参数
     * @author dazongzi
     * @since 2025-07-10
     */
    //@PreAuthorize("hasAuthority('platform:activitystyle:list')")
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/page/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<TraceableOrderPageDataBrandResponse>> getList(@Validated TraceableOrderSearchBrandRequest request,
                                                                   @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<TraceableOrderPageDataBrandResponse> traceableOrderCommonPage = CommonPage.restPage(traceableOrderService.getListBrand(request, pageParamRequest));
        return CommonResult.success(traceableOrderCommonPage);
    }

    /**
     * 批量删除
     * @param request
     * @return
     * @author dazongzi
     * @since 2025-07-10
     */
    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "批量删除溯源套餐")
    @ApiOperation(value = "批量删除")
    @RequestMapping(value = "/batch/delete", method = RequestMethod.POST)
    public CommonResult<String> batchDelete(@RequestBody @Validated CommonBatchRequest request) {
        if (traceableOrderService.batchDelete(request.getIdList())) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 查询溯源订单表详情
     * @param id Integer
     * @author dazongzi
     * @since 2025-07-10
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    public CommonResult<TraceableOrderDetailBrandResponse> getDetails(@PathVariable("id") Integer id) {
        return CommonResult.success(traceableOrderService.getDetailsBrand(id));
    }

}



